package com.justech.mes.utils.plugins.transfer;

/**
 * Data format converter, where conversion logic is invoked
 * Use it only when converting in @Format mode.
 * Although we think this writing style is not elegant,
 * it was the fastest way to achieve data conversion function in the first place.
 *
 * @author feifei.li
 * @auther fly·Li
 */
public class Converter {

    public static Object convert(Class<?>[] converters, Object value) {
        for (Class<?> converter : converters) {
            value = convert(converter, value);
        }
        return value;
    }

    public static Object convert(Class<?> converter, Object value) {
        Object instance = ReflexUtilSandBox.getInstance(converter);
        DataFormatConverter dataFormatConverter = (DataFormatConverter) instance;
        value = dataFormatConverter.convert(value);
        return value;
    }
}
